package com.qmq.app.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qmq.app.annotation.Login;
import com.qmq.app.entity.EarningsEntity;
import com.qmq.app.service.QmqEarningsService;
import com.qmq.common.utils.Constant;
import com.qmq.common.utils.PageUtils;
import com.qmq.common.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/app")
public class AppQmqEarningsController {

    @Resource
    private QmqEarningsService earningsService;

    @Login
    @GetMapping("/earnings/page")
    public R page(@RequestParam Map<String, Object> params) {
        PageUtils page = earningsService.queryPage(params);
        return R.ok().put("data", page);
    }

    @Login
    @PostMapping("/earnings/add")
    public R add(@RequestBody EarningsEntity dto) {
        earningsService.add(dto);
        return R.ok("添加数据成功");
    }

    @Login
    @GetMapping("/earnings/get/{id}")
    public R get(@PathVariable("id") Long id) {
        return R.ok().put("data", earningsService.getOne(Wrappers.<EarningsEntity>lambdaQuery()
                .eq(EarningsEntity::getId, id)
                .last(Constant.SEARCH_ONE)));
    }

    @Login
    @PostMapping("/earnings/update")
    public R update(@RequestBody EarningsEntity dto) {
        earningsService.updateByDto(dto);
        return R.ok("更新数据成功");
    }

    @Login
    @GetMapping("/earnings/delete/{id}")
    public R delete(@PathVariable("id") Long id) {
        earningsService.delete(id);
        return R.ok("删除数据成功");
    }
}
